package cc.magicjson.synthesis.factory;


import cc.magicjson.synthesis.decorator.CompositeDiscountDecorator;
import cc.magicjson.synthesis.decorator.CouponDiscountDecorator;
import cc.magicjson.synthesis.decorator.OrderDiscountDecorator;
import cc.magicjson.synthesis.decorator.PointsDiscountDecorator;
import cc.magicjson.synthesis.model.Order;

/**
 * 订单折扣装饰器工厂，用于创建各种折扣装饰器
 */
public class OrderDiscountDecoratorFactory {

    /**
     * 创建积分折扣装饰器
     * @param order 订单
     * @param pointsPerYuan 积分兑换比例：多少积分兑换1元
     * @return 积分折扣装饰器
     */
    public static OrderDiscountDecorator createPointsDecorator(Order order, int pointsPerYuan) {
        return new PointsDiscountDecorator(order, pointsPerYuan);
    }

    /**
     * 创建优惠券折扣装饰器
     * @param order 订单
     * @return 优惠券折扣装饰器
     */
    public static OrderDiscountDecorator createCouponDecorator(Order order) {
        return new CouponDiscountDecorator(order);
    }

    /**
     * 创建组合折扣装饰器，包含积分和优惠券折扣
     * @param order 订单
     * @param pointsPerYuan 积分兑换比例：多少积分兑换1元
     * @return 组合折扣装饰器
     */
    public static CompositeDiscountDecorator createCompositeDecorator(Order order, int pointsPerYuan) {
        CompositeDiscountDecorator composite = new CompositeDiscountDecorator(order);
        composite.addDecorator(createPointsDecorator(order, pointsPerYuan))
                .addDecorator(createCouponDecorator(order));
        return composite;
    }
}
